<template>
    <div class="group-management">
        <div class="search-content">
            <!-- <el-input class="search-content-input" style="width: 0;visibility: visible;" v-model="searchContent.groupId" placeholder="请输入活动ID"></el-input> -->
            
           
            <div class="time-range-wrapper" >
                <!-- <span class="time-range-label">请选择活动时间：</span> -->
                <el-date-picker
                        v-model="searchContent.groupTime"
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期">
                </el-date-picker>
			</div>
			<span style="font-size: 14px;margin-left: 10px;" class="time-range-label">交易金额：</span>
            <el-input class="search-content-input" v-model="searchContent.userName" ></el-input>~
            <el-input class="search-content-input" v-model="searchContent.userPhone" ></el-input>
			<el-input class="search-content-input" v-model="searchContent.groupName" placeholder="请输入编号"></el-input>
           
			<el-select v-model="searchContent.class" placeholder="请选择分类">
                <el-option
                        v-for="item in search_status"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                </el-option>
            </el-select>
            <el-button type="primary" @click="search">搜索</el-button>
            <el-button type="primary" @click="resetSearchData">重置</el-button>
        </div>
        <div class="search-list">
            <el-table :data="groupList" border :height="oHeight">
                <el-table-column
                        align="center"
                        prop="id"
                        label="ID"
                        min-width="60"></el-table-column>
                <el-table-column
                        align="center"
                        prop="sn"
                        label="打款ID"
                        min-width="120"></el-table-column>
                <el-table-column
                        align="center"
                        prop="name"
                        label="名称"
						min-width="120"></el-table-column>
						
          
                <el-table-column
                        align="center"
                        prop="addtime"
                        label="生成时间"
                        min-width="90">
                  
                </el-table-column>
                <el-table-column
						align="center"
						prop="submittime"
                        label="提交银行时间"
                        min-width="90">
                    
				</el-table-column>
				<el-table-column
				align="center"
				prop="money"
				label="打款总金额"
				min-width="120">
			</el-table-column>
			<el-table-column
				align="center"
			
				label="状态"
				min-width="120">
				 <template slot-scope="scope">
                        {{computedCheckStatus(scope.row.status)}}
                    </template>
			</el-table-column>
			<el-table-column
				align="center"
				prop="sap_id"
				label="过账"
				min-width="120">
			</el-table-column>

                <el-table-column
                        align="center"
                        label="操作"
						min-width="240">
						<!-- v-if="scope.row.status == 1" -->
                    <template slot-scope="scope">
                        <el-button type="primary" @click="showFn(scope.row.id)">查看明细</el-button>
						<el-button type="warning" v-if="scope.row.lock_button_show == 1"  @click="showGroupDialog(scope.row,'1')">解锁订单</el-button>
						<el-button type="warning" v-if="scope.row.sync_button_show == 1"  @click="showGroupDialog(scope.row,'2')">同步状态</el-button>
						<el-button type="warning" v-if="scope.row.post_button_show == 1"  @click="showGroupDialog(scope.row,'3')">过账</el-button>
						<el-button type="warning" v-if="scope.row.submit_button_show == 1"  @click="showGroupDialog(scope.row,'4')">提交银行</el-button>

                    </template>
                </el-table-column>
            </el-table>
            <div class="bottom">
                <div class="btn-group" >
					<!-- <el-button type="primary" @click="showFn">新增项目券</el-button> -->
                </div>
                <div class="paginationOne">
                    <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="searchContent.currentPage"
                            :page-sizes="[10, 20, 50, 100]"
                            :page-size="searchContent.pageSize"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="total">
                    </el-pagination>
                </div>
            </div>
		</div>
		       <el-dialog
                :before-close="handlecheckClose"
                title="提示"
                :visible="checkdialog"
				width="30%">
				<input type="radio" id="male" value="1" v-model="gender"> 通过

				<input type="radio" id="female" value="0" v-model="gender"> 未通过
				<!-- <el-select v-model="searchContent.check" placeholder="请选择审核状态">
					<el-option
							v-for="item in check"
							:key="item.value"
							:label="item.label"
							:value="item.value">
					</el-option>
				</el-select> -->
            <span slot="footer" class="dialog-footer">
                <el-button @click="handlecheckClose">取 消</el-button>
                <!-- <el-button type="primary" @click="confirmcheck">确 定</el-button> -->
				<el-button type="primary">确 定</el-button>
            </span>
        </el-dialog>
        <el-dialog
                :before-close="handleClose"
                title="提示"
                :visible="dialogVisible"
                width="30%">
            <span>{{dialogMsg}}</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="handleClose">取 消</el-button>
                <el-button type="primary" @click="confirmClose">确 定</el-button>
            </span>
		</el-dialog>
		<default-opr ref="ceshi"></default-opr>
    </div>
</template>

<script>
	import { resize } from "@/common/js/height.js";
    import {dateFormatter} from "../../../../common/js/util";
	import Qs from 'qs';
	import defaultOpr from './default-opr';
	export default {
		components: {defaultOpr},
		data() {
			return {
				options: [
					
					{label: '开启', value: 1},
					{label: '关闭', value: 2}
				],check: [
					{label: '通过', value: 1},
					{label: '未通过', value: 0}
					
				],search_status: [
					
					
				],
				oHeight: 800,
				searchContent: {
					groupId: '',
					userName:'',
					userPhone:'',
					groupName: '',
					storeName: '',
					addTime: '',
					groupTime: '',
					status: '',
					check: '',
					currentPage: 1,
					pageSize: 10
				},
				gender: '',
				needCloseGoods: null,
				dialogVisible: false,
				checkdialog:false,
				dialogMsg: '',
				groupList: [],
				total: 0
			}
		},
		computed: {
			exportLink() {
				const data = {};
				data.export = 'yes';
				data.id = this.searchContent.groupId;
				data.title_name = this.searchContent.groupName;
				data.store_name = this.searchContent.storeName;
				let domain = document.domain;
				if (domain != 'admin.mycjj.com' && domain != 'admin.chejj.cn') {
					domain = 'admin.chejj.cn'
				}
				return location.protocol + '//' + domain.replace('admin', 'api') + '/admin/afterSalesGroupBuy/index.php?act=groupBuy&op=list&' + Qs.stringify(data);
			}
		},
		methods: {
			copyLink(url) {
				var cText = url ? url : document.location.href;
				var aux = document.createElement("input");
				aux.setAttribute("value", cText);
				document.body.appendChild(aux);
				aux.select();
				document.execCommand("copy");
				document.body.removeChild(aux);
				alert("链接复制成功!");
			},
			showFn(data){
			this.$refs.ceshi.show_dialog_fn(data);
		},
			handch(item, id) {
				const data = {};
				data.brand_group_id = item;
				data.brand_group_sort = id;
				this.$http.post('/admin/brandgroup/index.php?act=brandgroup&op=editSort', data).then(res => {
					if (res.code == 1) {
					this.getListData();
					}
					else {
						// alert(res.msg+"88");
					}
				})
    //   console.log('我是id:', item, ',我是需要改变的值:', id)
        },
			closeGroup(group) {
				 console.log(group.groupId);
				this.$http.post('/admin/platform_coupon/index.php?act=platform_coupon&op=close', {
					id: group.groupId
				}).then(res => {
					if (res.code == 1) {
				
               
						
						this.handleClose();
						this.getListData();
						
					} else {
						
						alert(res.msg)
					}
				})
			},
			checkGroup(group,check) {
				console.log(group);
			    if(check=="1"){
					const data = {};
				data.id = group;

				this.$http.post('/admin/bill/index.php?act=reconciliation&op=unlockOrder', {
					id : group.id
				   

				}).then(res => {
					if (res.code == 1) {
					
						this.handleClose();
						this.handlecheckClose();
						this.getListData();
						
					} else {
						this.handleClose();
						this.handlecheckClose();
						alert(res.msg);
					}
				})
				}else if(check=="2"){
					const data = {};
				data.id = group;

				this.$http.post('/admin/bill/index.php?act=reconciliation&op=syncState', {
					id : group.id
				   

				}).then(res => {
					if (res.code == 1) {
						
						this.handleClose();
						this.handlecheckClose();
						this.getListData();
						
					} else {
						this.handleClose();
						this.handlecheckClose();
						alert(res.msg);
					}
				})
				}else if(check=="3"){
				this.$http.post('/admin/bill/index.php?act=reconciliation&op=posting', {
					id:group.id,type:group.type
				   

				}).then(res => {
					if (res.code == 1) {
						
						this.handleClose();
						this.handlecheckClose();
						this.getListData();
						
					} else {
						this.handleClose();
						this.handlecheckClose();
						alert(res.msg);
					}
				})
				}else if(check=="4"){
					this.$http.post('/admin/bill/index.php?act=reconciliation&op=submitBank', {
						id:group.id
					}).then(res => {
						if (res.code == 1) {
							this.handleClose();
							this.handlecheckClose();
							this.getListData();	
						} else {
							this.handleClose();
							this.handlecheckClose();
							alert(res.msg);
						}
					})
				}
			},
			showGroupDialog(groupItem,i) {
				console.log(groupItem.id); 
				this.needCloseGroup = groupItem;
				console.log('9999',groupItem);
				this.gender=i;
				if(i==="1"){
					this.dialogMsg = '确定要解锁此订单？';
				}else if(i==="2"){
					this.dialogMsg = '确定要同步此订单？';
				}else if(i==="3"){
					this.dialogMsg = '确定要过账此订单？';
				}else if(i==="4"){
					this.dialogMsg = '确定要提交银行？';
				}
				
				this.dialogVisible = true;
			},
			handleClose() {
				this.dialogVisible = false;
				this.dialogMsg = '';
				this.needCloseGroup = null;
			},
			showcheckDialog(groupItem) {
			//  console.log(groupItem);
			
				this.$router.push(`/home/operate-panel/project-voucher/group-edit?id=${groupItem}`) ;

			},
			handlecheckClose() {
				this.checkdialog = false;
				this.needCloseGroup = null;
			},
			confirmClose() {
				this.checkGroup(this.needCloseGroup,this.gender);
			},
			
			computedCheckStatus(code) {
				for(var j=0;j<this.search_status.length;j++){  
   
           if(code==this.search_status[j].value){
		
          return this.search_status[j].label;
     
  
      }
    }
			},
			resetSearchData() {
				this.searchContent.groupId = '';
				this.searchContent.groupName = '';
				this.searchContent.userName = '';
				this.searchContent.userPhone = '';
			
				this.searchContent.storeName = '';
				this.searchContent.addTime = '';
				this.searchContent.groupTime = '';
				this.searchContent.status = '';
				this.searchContent.class = '';
				this.getListData();
			},
			search() {
				this.searchContent.currentPage = 1;
				this.getListData();
			},
			handleSizeChange(pageSize) {
				this.searchContent.pageSize = pageSize;
				this.searchContent.currentPage = 1;
				this.getListData();
			},
			handleCurrentChange(page) {
				this.searchContent.currentPage = page;
				this.getListData();
			},
			getStaus() {
				

				this.$http.post('/admin/bill/index.php?act=reconciliation&op=getBankStatuses').then(res => {
					if (res.code == 1) {
						if (res.data && res.data.length) {
							this.search_status=res.data;
							console.log(this.search_status);
							
							
							
						}
					}
					
					
				})
			},
			getListData() {
				const data = {};
				data.page = this.searchContent.currentPage;
				data.pageSize = this.searchContent.pageSize;
				data.sn = this.searchContent.groupName;
				data.money_start = this.searchContent.userName;
				data.money_end = this.searchContent.userPhone;
				
				if (this.searchContent.addTime) {
					const startAddMS = this.searchContent.addTime[0].getTime();
					const endAddMS = this.searchContent.addTime[1].getTime();
					if (startAddMS == endAddMS) {
						data.start_addtime = dateFormatter('YYYY-MM-DD HH:mm:ss', startAddMS);
						data.end_addtime = dateFormatter('YYYY-MM-DD HH:mm:ss', endAddMS + (24 * 60 * 60 - 1) * 1000);
                    } else {
						data.start_addtime = dateFormatter('YYYY-MM-DD HH:mm:ss', this.searchContent.addTime[0]);
						data.end_addtime = dateFormatter('YYYY-MM-DD HH:mm:ss', this.searchContent.addTime[1]);
                    }
				}
				if (this.searchContent.groupTime) {
					const startMS = this.searchContent.groupTime[0].getTime();
					const endMS = this.searchContent.groupTime[1].getTime();
					if (startMS == endMS) {
						data.addtime_start = dateFormatter('YYYY-MM-DD HH:mm:ss', startMS);
						data.addtime_end = dateFormatter('YYYY-MM-DD HH:mm:ss', endMS + (24 * 60 * 60 - 1) * 1000);
					} else {
						data.addtime_start = dateFormatter('YYYY-MM-DD HH:mm:ss', startMS);
						data.addtime_end = dateFormatter('YYYY-MM-DD HH:mm:ss', endMS);
					}
				}
		
				data.status = this.searchContent.class;

				this.$http.post('/admin/bill/index.php?act=reconciliation&op=pay', data).then(res => {
					if (res.code == 1) {
						if (res.data && res.data.list.length) {
							this.groupList = res.data.list.map(function(item) {
								return {
									
									id: item.id,
									sn: item.sn,
									name: item.name,
									addtime:item.addtime,
									submittime:item.submittime,
                                    sap_id:item.sap_id,
									money:item.money,
									status:item.status,
									pc_sum:item.pc_sum,
									SerialNo:item.SerialNo,
									is_Unlock:item.is_Unlock,
									sync_button_show:item.sync_button_show,
									post_button_show:item.post_button_show,
									lock_button_show:item.lock_button_show,
									submit_button_show:item.submit_button_show,
									type:item.type,

									
									
								}
							});
							this.total = parseInt(res.data.totalCount);
							
							
						} else {
							this.groupList = [];
							this.total = 0;
						}
					}
					else if (res.code == 2001) {
						this.groupList = [];
						this.total = 0;
					}
					else {
						alert(res.msg);
					}
				})
			},
			goCheckGroup(group) {
				if (group.status == 0 || group.status == 4) {
					return;
                }
				// this.$router.push(`/home/operate-panel/car-group/group-detail?id=${group.groupId}`)
			}
		},
		mounted() {
			resize(this)
		},
		created() {
			this.$parent.tabLists = [
			{"label": "支付对账", "name": 'sign-up-info'},
			 {"label": "打款过账", "name": 'group-management'},
            ]
			this.getListData();
			this.getStaus();
		},
		name: "group-management"
	}
</script>

<style lang="scss" scoped>
    .group-management {
        .search-content {
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            &-input {
                width: 200px;
            }
            .time-range-wrapper {
                .time-range-label {
                    font-size: 14px;
                }
                display: flex;
                align-items: center;
                /deep/.el-range-separator {
                    box-sizing: content-box;
                }
            }
        }
        .bottom {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
    }
    .btn-bottom {
        background: #409EFF;
        color: #fff;
        border: 0;
        font-size: 14px;
        padding: 5px 8px;
        border-radius: 3px;
        display: inline-block;
    }
</style>